<%@page import="org.sysmhg.util.Constants"%>
<script type="text/javascript">
Ext.namespace('Ext.org.sysmhg.base.customer');

Ext.org.sysmhg.base.customer.CustomerFormPanelTopBar = function(config) {
	
	this.customerFormPanel = null;

	this.setCustomerFormPanel = function(customerFormPanel){
		this.customerFormPanel = customerFormPanel;
	}

	this.btnSave = new Ext.Button({
        text: 'Save',
        icon:'<%=Constants.imgPathBtnSave%>',
        cls:"x-btn-text-icon",
        scope:this,
        handler: customerTopBar_save
    });
	
    
	config.items  = [
	    this.btnSave
	];
	Ext.org.sysmhg.base.customer.CustomerFormPanelTopBar.superclass.constructor.call(this, config);
	
	
	<%-- 
	Funcion para el boton Save del top bar
	--%>
	function customerTopBar_save(){
		this.customerFormPanel.getForm().submit({
			url: 'Customer.htm',
			method: 'POST',
			scope: this,
			params:{
				action:'createOrUpdateCustomer'
			},
			success: function(form, action){
				var jsonResponse = Ext.util.JSON.decode(action.response.responseText);
				this.customerFormPanel.hdnCustomerId.setValue(jsonResponse.customer_id);
				Ext.MessageBox.alert('Ok', jsonResponse.message); 		
			},failure: function(form, action){
				var jsonResponse = Ext.util.JSON.decode(action.response.responseText);
				Ext.MessageBox.alert('Error', jsonResponse.message); 	
			}
		});
	}
	
}

Ext.extend(Ext.org.sysmhg.base.customer.CustomerFormPanelTopBar, Ext.Toolbar, {		
});

</script>